import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store'

Vue.use(VueRouter)

  const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('../views/Home')
    },
    {
      path: '/chat',
      name: 'Chat',
      component: () => import('../views/Chat'),
      beforeEnter: (to, from, next) => {
        let intervalId = setInterval(() => {
          // 直到store中isSuccessConnect为true时才能进入/page
          if (store.getters.getIsSuccessConnect) {
            clearInterval(intervalId)
            next()
          }
        }, 500)
      }
    },
    {
      path: '/steps',
      name: 'Steps',
      component: () => import('../views/Steps')
    }
]

const router = new VueRouter({
  routes
})

export default router
